package com.example.travel_front.Fragment;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.travel_front.Adapter.DiscoverTravelerAdapter;
import com.example.travel_front.Adapter.TopicAdapter;
import com.example.travel_front.Model.Topic;
import com.example.travel_front.Model.Traveler;
import com.example.travel_front.R;

import java.util.ArrayList;
import java.util.List;

public class FeedFragment extends Fragment {

    public FeedFragment() {
        // Required empty public constructor
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_feed, container, false);
    }

    @Override
    public void onViewCreated(@NonNull View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);

        RecyclerView rvDiscoverTravelers = view.findViewById(R.id.rvDiscoverTravelers);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
        rvDiscoverTravelers.setLayoutManager(layoutManager);

        List<Traveler> travelers = getTravelers();
        DiscoverTravelerAdapter adapter1 = new DiscoverTravelerAdapter(travelers);
        rvDiscoverTravelers.setAdapter(adapter1);

        RecyclerView rvTopic = view.findViewById(R.id.rvTopic);
        LinearLayoutManager layoutManagerPopular = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
        rvTopic.setLayoutManager(layoutManagerPopular);

        List<Topic> topics = getTopics();
        TopicAdapter adapter2 = new TopicAdapter(topics);
        rvTopic.setAdapter(adapter2);
    }

    private List<Topic> getTopics() {
        List<Topic> topics = new ArrayList<>();

        topics.add(new Topic("John Doe", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar1.png", "Can anyone recommend iconic spots in New York for photography?", 240, 12, "30 minutes ago"));
        topics.add(new Topic("Alice Johnson", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar2.png", "Looking for hidden gems in New York, any local favorites?", 112, 7, "1 hour ago"));
        topics.add(new Topic("Mark Smith", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar3.png", "What's the best way to spend a day in Central Park?", 340, 15, "2 hours ago"));
        topics.add(new Topic("Emily Davis", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar4.png", "Is the Statue of Liberty worth the visit? Any tips for a first-timer?", 621, 5, "3 hours ago"));
        topics.add(new Topic("Michael Brown", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar5.png", "Best historical museums in New York that are off the beaten path?", 159, 3, "1 day ago"));

        return topics;
    }


    private List<Traveler> getTravelers() {
        List<Traveler> travelers = new ArrayList<>();

        // 添加一些假数据
        travelers.add(new Traveler("Alice Smith", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar1.png", 120, 250));
        travelers.add(new Traveler("Bob Johnson", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar2.png", 85, 190));
        travelers.add(new Traveler("Charlie Williams", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar3.png", 200, 300));
        travelers.add(new Traveler("Diana Brown", "https://jdhn.oss-cn-hangzhou.aliyuncs.com/avatar4.png", 75, 110));


        return travelers;
    }

}
